package com.example.springcloud.consumer.student.controller;

import com.example.springcloud.common.entity.ResponseResult;
import com.example.springcloud.common.entity.Student;
import com.example.springcloud.consumer.student.cloudclient.StudentFeignClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/consumer/student")
public class ConsumerController {
    private StudentFeignClient studentFeignClient;

    @Resource
    public void setStudentFeignClient(StudentFeignClient studentFeignClient) {
        this.studentFeignClient = studentFeignClient;
    }

    @GetMapping("/{id}")
    public ResponseResult<?> getStudent(@PathVariable("id") int id) {
        return studentFeignClient.findStudent(id);
    }

    @GetMapping
    public ResponseResult<?> getAllStudent() {
        return studentFeignClient.findAllStudents();
    }

    @PutMapping
    public ResponseResult<?> addStudent(@RequestBody Student student) {
        return studentFeignClient.addStudent(student);
    }

    @DeleteMapping("/{id}")
    public ResponseResult<?> deleteStudent(@PathVariable("id") int id) {
        return studentFeignClient.deleteStudent(id);
    }
}